<?php
// $Id$

include_once('BaseModel.class.php');

class GroupManagementModel extends BaseModel {
    function collect($offset=null,$limit=null,$search=array(),$by='1',$sort='') {
        $where = ($search) ? "WHERE LOWER({$search['searchfield']}) LIKE '%{$search['searchtext']}%'" : "WHERE 1";

        if (is_null($offset)) {
            $query = "SELECT COUNT(*) FROM groups $where AND active=1";
        } else {
            $query = "SELECT * FROM groups $where AND active=1 ORDER BY $by $sort LIMIT $offset,$limit";
        }
        return $this->query($query, true);
    }

    function detail ($id) {
        $query = "SELECT * FROM groups WHERE id='$id'";
        return $this->query($query, true);
    }

    /*
     * Add groupss and return the new group_id
     *
     */
    function ins($detail) {
        return $this->insert('groups', $detail);
        return $this->last_insert_id('groups');
    }

    /*This will add new members within spesific group*/
    function add_gmembers($detail) {
        return $this->insert('group_members', $detail);
    }

    /*This will delete a member within spesific group*/
    function del_gmembers($id) {
        return $this->query("DELETE FROM group_members WHERE group_id = '$id';");
    }

    /*
     * Update groups for a particular group_id
     *
     */
    function edit ($id, $detail) {
        return $this->update('groups', $detail, "id = '$id'");
    }

    /*
     * Delete groups detail for a particular group_id
     *
     */
    function deactivate ($id) {
        $query = "UPDATE groups SET active = '0' WHERE id='$id'";
        return $this->query($query, false);
    }
    function activate ($id) {
        $query = "UPDATE groups SET active = '1' WHERE id='$id'";
        return $this->query($query, false);
    }
}

?>
